package Interfaz;

import Controladores.*;
import Interfaz.*;
import java.awt.List;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Adrian
 */
public class VentataReservaciones extends Ventana_Defaults {

    /**
     * Creates new form Reservaciones
     */
    Mesa m;
    Reservacion r;
    ResultSet rs;
    Orden orden;
    public VentataReservaciones() {
        
        
            initComponents();
            m = new Mesa();
            setSize(700, 700);
            r = new Reservacion();
            orden = new Orden();
            setLocationRelativeTo(null);
            setResizable(false);
            setTitle("Ver Reservaciones");
            try {
            rs = m.realizarConsulta("select nombre from reservacion r join mesa m where r.idreservacion=m.idReservacion;");
                System.out.println(rs);
            while(rs.next()){
                cmbNombre.addItem(rs.getString("nombre"));
            }
        } catch (SQLException ex) {
            Logger.getLogger(VentataReservaciones.class.getName()).log(Level.SEVERE, null, ex);
        }
            btnAsignar.setVisible(false);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        btnAsignar = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        btnAtras1 = new javax.swing.JButton();
        cmbNombre = new javax.swing.JComboBox();
        jLabel25 = new javax.swing.JLabel();
        lblMesa = new javax.swing.JLabel();
        cmdActualizar = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setAlwaysOnTop(true);
        getContentPane().setLayout(null);

        btnAsignar.setFont(new java.awt.Font("AR CENA", 0, 18)); // NOI18N
        btnAsignar.setText("Asignar Mesa");
        btnAsignar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAsignarActionPerformed(evt);
            }
        });
        getContentPane().add(btnAsignar);
        btnAsignar.setBounds(340, 170, 190, 33);

        jLabel1.setFont(new java.awt.Font("AR CENA", 0, 18)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(255, 255, 255));
        jLabel1.setText("Nombre del Cliente");
        getContentPane().add(jLabel1);
        jLabel1.setBounds(40, 60, 160, 24);

        btnAtras1.setFont(new java.awt.Font("AR CENA", 0, 14)); // NOI18N
        btnAtras1.setText("Atras");
        btnAtras1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAtras1ActionPerformed(evt);
            }
        });
        getContentPane().add(btnAtras1);
        btnAtras1.setBounds(20, 20, 73, 23);
        getContentPane().add(cmbNombre);
        cmbNombre.setBounds(220, 60, 120, 20);

        jLabel25.setFont(new java.awt.Font("Microsoft Sans Serif", 1, 14)); // NOI18N
        jLabel25.setForeground(new java.awt.Color(255, 255, 255));
        jLabel25.setText("Mesa Asignada:");
        getContentPane().add(jLabel25);
        jLabel25.setBounds(50, 130, 120, 16);

        lblMesa.setFont(new java.awt.Font("Microsoft Sans Serif", 1, 14)); // NOI18N
        lblMesa.setForeground(new java.awt.Color(255, 255, 255));
        lblMesa.setText("Mesa asignada");
        getContentPane().add(lblMesa);
        lblMesa.setBounds(180, 130, 120, 16);

        cmdActualizar.setFont(new java.awt.Font("Microsoft Sans Serif", 0, 18)); // NOI18N
        cmdActualizar.setText("Actualizar Datos");
        cmdActualizar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdActualizarActionPerformed(evt);
            }
        });
        getContentPane().add(cmdActualizar);
        cmdActualizar.setBounds(380, 50, 170, 30);

        jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
        jLabel4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/interior.jpg"))); // NOI18N
        getContentPane().add(jLabel4);
        jLabel4.setBounds(-30, -40, 725, 600);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnAtras1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAtras1ActionPerformed
        this.dispose();
    }//GEN-LAST:event_btnAtras1ActionPerformed

    private void btnAsignarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAsignarActionPerformed
        r.eliminarReservacion(lblMesa.getText());
        m.desocuparMesa(lblMesa.getText(), 0);
        ComerAqui cm = new ComerAqui(lblMesa.getText(),0);
        cm.setVisible(true);
        dispose();
    }//GEN-LAST:event_btnAsignarActionPerformed

    private void cmbMesasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbMesasActionPerformed
        // TODO add your handling code here:
        
        
    }//GEN-LAST:event_cmbMesasActionPerformed

    private void cmdActualizarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdActualizarActionPerformed
        try {
            rs = r.getIdReservacionDeMesa(cmbNombre.getSelectedItem().toString());
            rs.next();
            lblMesa.setText(rs.getString("idMesa"));
        } catch (SQLException ex) {
            Logger.getLogger(VentataReservaciones.class.getName()).log(Level.SEVERE, null, ex);
        }
        btnAsignar.setVisible(true);
    }//GEN-LAST:event_cmdActualizarActionPerformed

    

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAsignar;
    private javax.swing.JButton btnAtras1;
    private javax.swing.JComboBox cmbNombre;
    private javax.swing.JButton cmdActualizar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel lblMesa;
    // End of variables declaration//GEN-END:variables


}
